import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
        title: '导航跳转',
        home: Shouye()
    );
  }
}

class Shouye extends StatelessWidget {
  const Shouye({Key? key}) : super(key: key);

  _navigatorToSelect(BuildContext context) async{
    final result = await Navigator.push(
      context,
      MaterialPageRoute(builder: (context)=>SelectXiaoJieJie())
    );
    // 显示一个消息提示
    ScaffoldMessenger.of(context)..hideCurrentSnackBar()..showSnackBar(SnackBar(content: Text('$result'),));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('点击按钮挑选小姐姐'),
      ),
      body: Center(
        child: ElevatedButton(
          child: const Text('去找小姐姐'),
          onPressed: (){
            _navigatorToSelect(context);
          },
        ),
      ),
    );
  }
}

class SelectXiaoJieJie extends StatelessWidget {

  const SelectXiaoJieJie({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('小姐姐列表页面'),
      ),
      body: ListView(
        children: [
          ListTile(
            title: const Text('长腿小姐姐'),
            subtitle: const Text('1511008888'),
            leading: const Icon(Icons.people),
            onTap: () {
              Navigator.pop(context, '大长腿:1511008888');
            },
          ),
          ListTile(
            title: const Text('大波小姐姐'),
            subtitle: const Text('1511006666'),
            leading: const Icon(Icons.people),
            onTap: () {
              Navigator.pop(context, '大波波:1511006666');
            },
          ),
          ListTile(
            title: const Text('小蛮腰小姐姐'),
            subtitle: const Text('1511009999'),
            leading: const Icon(Icons.people),
            onTap: () {
              Navigator.pop(context, '小蛮腰:1511009999');
            },
          )
        ],
      ),
    );
  }
}